﻿using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UMLSynthesizer.CSharpAnalyzer.Elements;
using UMLSynthesizer.LangAnalyzer.Elements;

namespace UMLSynthesizer.CSharpAnalyzer.Helpers
{
    class CSharpElementWithAccessorsHelper
    {
        #region Fields

        IElementWithAccessorsBase elementWithAccessors;
        SyntaxNode elementNode;
        IEnumerable<CSharpAccessorElement> _accessorList;

        #endregion

        #region Constructor

        public CSharpElementWithAccessorsHelper(
            IElementWithAccessorsBase elementWithAccessors,
            SyntaxNode elementNode)
        {
            this.elementWithAccessors = elementWithAccessors;
            this.elementNode = elementNode;
        }

        #endregion

        #region Properties

        public IEnumerable<IAccessorElement> Accessors
        {
            get
            {
                if (_accessorList == null)
                    _accessorList = from accessor in (elementNode as BasePropertyDeclarationSyntax).AccessorList.Accessors
                                    orderby accessor.Keyword.Text
                                    select new CSharpAccessorElement(accessor, elementWithAccessors);
                return _accessorList;
            }
        }

        #endregion
    }
}
